<template>
  <van-nav-bar @click-left="onClickLeft">
    <template #left>
      <van-icon name="arrow-left" color="#fff" />
    </template>
    <template #title>
      <span class="top-text">设备检测</span>
    </template>
  </van-nav-bar>

  <div :class="{ 'blue-line': !show }"></div>

  <div class="blue">
    <div class="blue-box">
      <span>开始检测后，记得开启相机和！</span>
      <span>麦克风访问权限哦！</span>
      <div>
        <img src="../assets/image/tests-img/222.png" alt="" />
        <i>摄像头</i>
      </div>
      <div>
        <img src="../assets/image/tests-img/444.png" alt="" />
        <i>麦克风</i>
      </div>
      <div>
        <img src="../assets/image/tests-img/333.png" alt="" />
        <i class="tag">扬声器</i>
      </div>
    </div>
  </div>

  <div class="blue-bottom">
    <van-button type="primary" size="large" color="#00B1FF" round @click="startgo">
      开始检测
    </van-button>
    <van-overlay :show="show" @click="startgo">
      <div class="circle">
        <van-circle
          v-model:current-rate="currentRate"
          :rate="rate"
          :speed="20"
          :text="text"
          :stroke-width="70"
          size="140px"
          :color="gradientColor"
        />
      </div>
    </van-overlay>
  </div>
</template>

<script>
import { ref, computed } from "vue";
export default {
  setup() {
    const onClickLeft = () => history.back();
    const show = ref(false);

    const currentRate = ref(0);
    const rate = ref(0);
    const gradientColor = {
      "0%": "#3fecff",
      "100%": "#6149f6",
    };
    const text = computed(() => currentRate.value.toFixed(0) + "%");

    const timer = () =>
      setInterval(() => {
        if (currentRate.value == 100) {
          clearInterval(timer);
          show.value = false;
        }
        rate.value += 10;
      }, 500);

    const startgo = () => {
      if (show.value) {
        show.value = false;
        clearInterval(timer);
      } else if (!show.value) {
        show.value = true;
        timer();
      }
    };

    return {
      onClickLeft,
      show,
      text,
      currentRate,
      startgo,
      rate,
      gradientColor,
    };
  },
};
</script>

<style lang="less" scoped>
.van-hairline--bottom {
  background: #1bd0fe;

  .top-text {
    color: #fff;
  }
}

.blue-line {
  width: 100%;
  height: 1px;
  position: absolute;
  background: #1bd0fe;
  top: 45px;
  z-index: 50;
}

.blue {
  width: 100%;
  height: 440px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #1bd0fe;

  .blue-box {
    width: 320px;
    height: 375px;
    background: white;
    border: #56d6fb 10px solid;
    border-radius: 20px;
    display: flex;
    align-items: center;
    flex-direction: column;
    padding-top: 20px;
    box-shadow: 0 0 30px #046ae1;

    > span {
      font-size: 18px;
      margin-top: 5px;
    }

    > div {
      display: flex;
      align-items: center;
      margin-top: -10px;
      margin-left: -20px;
      > img {
        transform: scale(0.5);
      }

      > i {
        font-size: 16px;
        color: lightgray;
        font-weight: 600;
        margin-left: 20px;
      }

      > .tag {
        margin-left: 4px;
      }
    }
  }
}

.blue-bottom {
  width: 100%;
  height: 180px;
  background: #046ae1;
  display: flex;
  align-items: center;
  justify-content: center;
  > .van-button {
    width: 300px;
  }
}

.circle {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;

  /deep/.van-circle__text {
    color: #fff;
  }
}
</style>
